package com.example.capsule_netty.protocol;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @Author: zhuzhiming
 * @Date: 2022/5/9 12:18
 */
public class MessageBeanEncoder extends MessageToByteEncoder<MessageBeanProtocol> {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, MessageBeanProtocol messageBeanProtocol, ByteBuf byteBuf) throws Exception {
        byteBuf.writeInt(messageBeanProtocol.getLen());
        byteBuf.writeBytes(messageBeanProtocol.getContent());
    }
}
